package com.ztsjglxt.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ztsjglxt.controller.base.BaseController;
import com.ztsjglxt.core.IProjectfields;
import com.ztsjglxt.core.Ibasecommon;
import com.ztsjglxt.entity.Projectfields;
import com.ztsjglxt.entity.utils.JsonWrite;
import com.ztsjglxt.utils.Laypage;
import com.ztsjglxt.utils.PageUtil;

/**
 * 项目领域管理
 * @author bxf
 *
 */
@Controller
@RequestMapping("sys/sysprojectfields")
public class ProjectfieldsController extends BaseController{
		
	@Autowired
	Ibasecommon bllbase;
	@Autowired
	private IProjectfields  projectfieldsservice;
	/**
	 * 跳转值项目领域管理页面
	 * @param pid
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/fdProjectfieldspage")
	public String fdProjectfieldsList(String pid ,HttpServletRequest request ,HttpServletResponse response){
		
		request.setAttribute("buttom", this.outputbtn(pid, bllbase));
		return "projectfields/projectfields";
	}
	
	/**
	 * 分页获取对象信息
	 * @param page
	 * @param request
	 * @param response
	 */
	@RequestMapping("/getlist")
	public void getlist(PageUtil page,HttpServletRequest request ,HttpServletResponse response){
		
		try{	
			Laypage page1 = projectfieldsservice.getlistpager(page);
			jsonWrite.setSuccess(true);
			jsonWrite.setObj(page1);
		} 
		catch (Exception e) {
			jsonWrite.setSuccess(false);
			e.printStackTrace();
		}
		this.writeJson(response, jsonWrite);
	}
	/**
	 * 跳转至添加页面
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/fdaddparea")
	public String fdaddparea(HttpServletRequest request,HttpServletResponse response){
		return "projectfields/eduit/addproject";
	}
	/**
	 * 添加项目领域
	 * @param request
	 * @param response
	 * @param entity
	 */
	@RequestMapping("/addparea")
	public void addparea(HttpServletRequest request,HttpServletResponse response,Projectfields entity){
		JsonWrite jsonwrite = new JsonWrite();
		int count = projectfieldsservice.insertSelective(entity);
		if(count>0){
			jsonwrite.setSuccess(true);
		}else{
			jsonwrite.setSuccess(false);
		}
		this.writeJson(response, jsonwrite);
	}
	/**
	 * 更新项目领域
	 * @param request
	 * @param response
	 * @param entity
	 */
	@RequestMapping("/updateparea")
	public void updateparea(HttpServletRequest request,HttpServletResponse response,Projectfields entity){
		JsonWrite jsonwrite = new JsonWrite();
		int count = projectfieldsservice.updateParea(entity);
		if(count>0){
			jsonwrite.setSuccess(true);
		}else{
			jsonwrite.setSuccess(false);
		}
		this.writeJson(response, jsonwrite);
	}
	/**
	 * 跳转值项目领域管理页面
	 * @param request
	 * @param response
	 * @param entity
	 * @return
	 */
	@RequestMapping("/fdupdateparea")
	public String fdupdateparea(HttpServletRequest request,HttpServletResponse response,Projectfields entity){
		
		Projectfields record = projectfieldsservice.selectlistbyid(entity);
		request.setAttribute("projectfield", record);
		return "projectfields/eduit/updateproject";
	}
	/**
	 * 根据条件获取满足条件的对象数量
	 * @param request
	 * @param response
	 * @param search
	 */
	@RequestMapping("/getcount")
	public void getcount(HttpServletRequest request,HttpServletResponse response,String search){
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("search", search);
		int count = projectfieldsservice.getcount(map);
		JsonWrite jsonwrite = new JsonWrite();
		if(count>0){
			jsonwrite.setSuccess(false);
		}else{
			jsonwrite.setSuccess(true);
		}
		this.writeJson(response, jsonwrite);
	}
	/**
	 * 删除对象
	 * @param request
	 * @param response
	 * @param ids
	 * @throws Exception
	 */
	@RequestMapping("/deleteparea")
	public void deleteparea(HttpServletRequest request,HttpServletResponse response,String ids) throws Exception{
		Map<String,Object> map = new HashMap<String,Object>();
		int count = projectfieldsservice.deleteparea(ids);
		JsonWrite jsonwrite = new JsonWrite();
		if(count>0){
			jsonwrite.setSuccess(true);
		}else{
			jsonwrite.setSuccess(false);
		}
		this.writeJson(response, jsonwrite);
	}
}
